package com.dom.stor.dao.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dom.stor.dao.entity.TGoodsInfo;
import com.dom.stor.dao.mapper.TGoodsInfoMapper;
import com.dom.stor.dao.service.ITGoodsInfoService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * B_商品信息 服务实现类
 * </p>
 *
 * @author xllei
 * @since 2018-11-17
 */
@Service
public class TGoodsInfoServiceImpl extends ServiceImpl<TGoodsInfoMapper, TGoodsInfo> implements ITGoodsInfoService {
    @Override
    public Map<Integer, TGoodsInfo> getGoodInfoList(Integer memCode) {
        List<TGoodsInfo> goodsInfos = getGoodList(memCode);
        return goodsInfos.stream().collect(Collectors.toMap(TGoodsInfo::getGoodCode, entity->{return entity;}));
    }

    @Override
    public Map<Integer, String> getGoodNameList(Integer memCode) {
        List<TGoodsInfo> goodsInfos = getGoodList(memCode);

        return goodsInfos.stream().collect(Collectors.toMap(TGoodsInfo::getGoodCode, entity->{return entity.getGoodName();}));
    }

    private List<TGoodsInfo> getGoodList(Integer memCode){
        Wrapper<TGoodsInfo> wrapper = new EntityWrapper<>();
        wrapper.eq("mem_code", memCode)
                .orderBy("id");
        return this.selectList(wrapper);
    }

    @Override
    public TGoodsInfo getGoodInfo(Integer memCode, Integer goodCode) {
        Wrapper<TGoodsInfo> wrapper = new EntityWrapper<>();
        wrapper.eq("mem_code", memCode)
                .and().eq("good_code", goodCode);
        return this.selectOne(wrapper);
    }
}
